//
//  clsAntsService.m
//  AntsExpress
//
//  Created by slccper on 16/1/3.
//  Copyright © 2016年 slccper. All rights reserved.
//

#import "clsAntsService.h"
#import "clsOtherFun.h"
#import "clsBannerSetting.h"
const int Ants_Login=0;
const int Ants_GetAreaList=1;
const int Ants_Register=2;
const int Ants_GetHotNews=3;
const int Ants_GetProblemExpressList=4;
const int Ants_GetProbleExpressByid=5;
const int Ants_GetSlideBox=6;
const int Ants_GetUserInfo=7;
const int Ants_GetQuHuoAdress=8;
const int Ants_GetBranchList=9;
const int Ants_GetHotNewsEntity=10;
const int Ants_GetWareList=11;
const int Ants_UpdateQuHuoAdress=12;
const int Ants_GetPickUpPoint=13;
const int Ants_ConvertToMyAccount=14;
const int Ants_MyExpressQuery=15;
const int Ants_MathExpress=16;
const int Ants_GetSendExpress=17;
const int Ants_UpLoadMemberPhoto=18;
const int Ants_GetTokenIOS=19;
const int Ants_GetTaoBaoAdress=20;
const int Ants_UpdateUser=21;
const int Ants_Updateuserpwd=22;
const int Ants_ResivePwd=23;
const int Ants_GetQuestionType=24;
const int Ants_GetQuestioTitle=25;
const int Ants_GetQuestionListTxt=26;
const int Ants_GetCity=27;
const int Ants_GetProvince=28;
const int Ants_GetDistrict=29;
const int Ants_SaveSendExpress=30;
const int Ants_DeleteSendExpress=31;
const int Ants_UpdateSendExpress=32;
const int Ants_GetAppNewVersion=33;
const int Ants_DeviceLoadImg=34;
const int Ants_GetBranchLists=35;
const int Ants_GetConSumpitionLog=36;
const int Ants_GetUserMoney=37;
@implementation clsAntsService
-(void) connection:(NSString *)method :(NSDictionary *)message{
    NSString *soapMessage;
//    if ([NSJSONSerialization isValidJSONObject:message])
//    {
//        NSError *error;
//        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:message options:NSJSONWritingPrettyPrinted error: &error];
//        soapMessage= [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
//    }
    soapMessage = [clsOtherFun getHttpBody:message];
    //请求发送到的路径
    NSURL *url = [NSURL URLWithString:[clsOtherFun getWSUrl:method]];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:kTimeoutInterval_WebService];
    
    //以下对请求信息添加属性前四句是必有的，第五句是soap信息。
    [theRequest addValue: @"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    
    //请求
//    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
//    //如果连接已经建好，则初始化data
//    if (theConnection) {
//        webData = [NSMutableData data];
//    }
    NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:theRequest completionHandler:^(NSData * _Nullable thewebData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        dispatch_async(dispatch_get_main_queue(), ^{
        theConnection = nil;
        dictionary = [NSMutableDictionary dictionary];
        NSString * data=[[NSString alloc] initWithData:thewebData encoding:NSUTF8StringEncoding];
        NSLog(@"return:%@",data);
        NSError * theerror=nil;
        if(thewebData){
            id obj=[NSJSONSerialization JSONObjectWithData:thewebData options:NSJSONReadingAllowFragments error:&theerror];
            if (theerror) {
                [self connectionFail];
                return;
            }
            if ([obj isKindOfClass:[NSDictionary class]]) {
                NSDictionary * dic=(NSDictionary *) obj;
                if(dic){
                    if (serviceType==Ants_GetSlideBox) {
                        NSArray *arr = [dic objectForKey:@"data"];
                        NSMutableArray *list = [NSMutableArray arrayWithArray:arr];
                        [dictionary setObject:list forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_Register) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_GetHotNews) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_GetProblemExpressList) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_GetProbleExpressByid) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_GetUserInfo) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_GetQuHuoAdress) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_GetHotNewsEntity) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_Login) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if (serviceType==Ants_GetPickUpPoint) {
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }else if(serviceType ==Ants_GetProvince){
                        if(self.action)
                            self.action(dic);
                    }else if(serviceType ==Ants_GetCity){
                        if(self.action)
                            self.action(dic);
                    }else if(serviceType ==Ants_GetDistrict){
                        if(self.action)
                            self.action(dic);
                    }else if(serviceType ==Ants_DeleteSendExpress){
                        if(self.action)
                            self.action(dic);
                    }else if(serviceType ==Ants_DeviceLoadImg){
                        if(self.action)
                            self.action(dic);
                    }
                    else{
                        [dictionary setObject:dic forKey:@"data"];
                        if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                            [self.delegate getAntsDataSuccess:serviceType :dictionary];
                        }
                    }
                    
                }
            }else if ([obj isKindOfClass:[NSArray class]]){
                NSArray *arr = (NSArray *)obj;
                [dictionary setObject:arr forKey:@"data"];
                if (serviceType==Ants_GetAreaList) {
                    if(self.action)
                        self.action(dictionary);
                }else if (serviceType==Ants_GetWareList) {
                    if(self.action)
                        self.action(dictionary);
                }else if (serviceType==Ants_GetBranchList) {
                    
                    if(self.action)
                        self.action(dictionary);
                }else if (serviceType==Ants_GetBranchLists){
                    if (self.action) {
                        self.action(dictionary);
                    }
                }
                else{
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }
            }
            
        }
        });
    }];
    [task resume];
}
- (void)GetDesStr:(NSString *)desstr
{
    serviceType = Ants_Login;
    NSDictionary *msg = @{@"str":desstr};
    [self connection:@"GetDesStr" :msg];
}
- (void)Login:(NSString *)uid :(NSString *)password
{
    serviceType = Ants_Login;
    NSDictionary *msg = @{@"name":uid,@"pwd":password};
    [self connection:@"Login" :msg];
}
- (void)GetUserInfoEntity:(NSString *)username
{
    serviceType = Ants_GetUserInfo;
    
    NSDictionary *msg = @{@"encodeName":username};
    [self connection:@"GetUserInfoEntity" :msg];
}

- (void)Register:(NSString *)RealName :(NSString *)MemberName :(NSString *)MemberPwd :(NSString *)ResivePwd :(NSString *)MemberPhone :(NSString *)aid :(NSString *)wid :(NSString *)bid :(NSString *)remark
{
    serviceType = Ants_Register;
    [self connection:@"Register" :@{@"RealName":RealName,@"MemberName":MemberName,@"MemberPwd":MemberPwd,@"ResivePwd":ResivePwd,@"MemberPhone":MemberPhone,@"aid":aid,@"wid":wid,@"bid":bid,@"remark":remark}];
}

- (void)GetQuHuoAdress:(NSString *)encodeName{
    serviceType = Ants_GetQuHuoAdress;
    [self connection:@"GetQuHuoAdress" :@{@"encodeName":encodeName}];
    
}
- (void)GetAreaList:(void(^)(NSDictionary *dic))action;{
    serviceType = Ants_GetAreaList;
    [self setAction:action];
    [self connection:@"GetAreaList" :@{}];
    
}
- (void)GetWareList:(NSString *)wid action:(void(^)(NSDictionary *dic))action
{
    serviceType = Ants_GetWareList;
    [self setAction:action];
    [self connection:@"GetWareList" :@{@"wid":wid}];

}
- (void)GetPickUpPoint:(NSString *)type
{
    serviceType = Ants_GetPickUpPoint;
    [self connection:@"GetPickUpPoint" :@{@"type":type}];
}
- (void)GetBranchList:(NSString *)wid action:(void(^)(NSDictionary *dic))action
{
    serviceType = Ants_GetBranchList;
    [self setAction:action];
    [self connection:@"GetBranchList" :@{@"wid":wid}];
}
- (void)GetBranchLists:(NSString *)wid action:(void(^)(NSDictionary *dic))action
{
    serviceType = Ants_GetBranchLists;
    [self setAction:action];
    [self connection:@"GetBranchLists" :@{@"wid":wid}];
}
- (void)GetConSumpitionLog:(NSString *)encodename :(NSUInteger)page
{
    serviceType = Ants_GetConSumpitionLog;
    [self connection:@"GetConSumpitionLog" :@{@"encodeName":encodename,@"page":[NSNumber numberWithInteger:page]}];
}
- (void)GetUserMoney:(NSString *)encodename
{
    serviceType = Ants_GetUserMoney;
    [self connection:@"GetUserMoney" :@{@"encodeName":encodename}];
}
-(void)UpdateQuHuoAdress:(NSString *)aid :(NSString *)bid :(NSString *)wid :(NSString *)areaRemark
{
    serviceType = Ants_UpdateQuHuoAdress;
    [self connection:@"UpdateQuHuoAdress" :@{@"wid":wid,@"bid":bid,@"aid":aid,@"areaRemark":areaRemark,@"encodeName":[clsOtherFun getencodeName]}];
}
- (void)GetProblemExpressList
{
    serviceType = Ants_GetProblemExpressList;
    [self connection:@"GetProblemExpressList" :@{}];
}
- (void)ConvertToMyAccount:(NSString *)Oid :(NSString *)encodename
{
    serviceType = Ants_ConvertToMyAccount;
    [self connection:@"ConvertToMyAccount" :@{@"Oid":Oid,@"encodeName":encodename}];
}
-(void)GetProbleExpressByid:(NSString *)idstr
{
    serviceType = Ants_GetProbleExpressByid;
    [self connection:@"GetProbleExpressByid" :@{@"id":idstr}];
}
- (void)GetSlideBox
{
    serviceType = Ants_GetSlideBox;
    [self connection:@"GetSlideBox" :@{}];
}
- (void)GetHotNews
{
    serviceType = Ants_GetHotNews;
    [self connection:@"GetHotNews" :@{}];
}
- (void)MyExpressQuery
{
    serviceType = Ants_MyExpressQuery;
    [self connection:@"MyExpressQuery" :@{@"encodeName":[clsOtherFun getencodeName]}];
}
- (void)GetHotNewsEntity:(NSString *)Entuty
{
    serviceType = Ants_GetHotNewsEntity;
    [self connection:@"GetHotNewsEntity" :@{@"id":Entuty}];
}
- (void)MathExpress:(NSString *)longs :(NSString *)width :(NSString *)height :(NSString *)weight :(NSString *)bid
{
    serviceType = Ants_MathExpress;
    [self connection:@"NewMathExpress" :@{@"long":longs,@"width":width,@"height":height,@"weight":weight,@"bid":[NSString stringWithFormat:@"%ld",[bid integerValue]]}];
}
- (void)GetSendExpress
{
    serviceType = Ants_GetSendExpress;
    [self connection:@"GetSendExpress" :@{@"uid":[clsOtherFun getMemberId]}];
}
- (void)UpLoadMemberPhoto:(NSData *)data
{
    serviceType = Ants_UpLoadMemberPhoto;
    NSString *str = [clsOtherFun base64forData:data];
    [clsOtherFun setTest:str];
    NSData *rrdata = [[NSData alloc]initWithBase64EncodedString:str options:NSDataBase64DecodingIgnoreUnknownCharacters];
    [self connection:@"UpLoadMemberPhoto" :@{@"encodeName":[clsOtherFun getencodeName],@"MemberPhoto":str}];
}
- (void)GetTokenIOS:(NSString *)name :(NSString *)token
{
    serviceType = Ants_GetTokenIOS;
    if ([token isEqualToString:@""]) {
        token=@"0";
    }
    [self connection:@"GetTokenIOS" :@{@"name":name,@"id":token,@"deviceType":@"1"}];
}
- (void)GetTaoBaoAdress
{
    serviceType = Ants_GetTaoBaoAdress;
    [self connection:@"GetTaoBaoAdress" :@{}];
}
- (void)UpdateUser:(NSString *)RealName :(NSString *)qq :(NSString *)wechart :(NSString *)Address :(NSString *)Email :(NSString *)MemberPhone :(NSString *)MemberSex
{
    serviceType = Ants_UpdateUser;
    [self connection:@"UpdateUser" :@{@"encodeName":[clsOtherFun getencodeName],@"RealName":RealName,@"qq":qq,@"wechart":wechart,@"Address":Address,@"Email":Email,@"MemberPhone":MemberPhone,@"MemberSex":MemberSex}];
}
- (void)Updateuserpwd:(NSString *)pwd
{
    serviceType = Ants_Updateuserpwd;
    [self connection:@"Updateuserpwd" :@{@"encodeName":[clsOtherFun getencodeName],@"pwd":pwd}];
}
- (void)ResivePwd:(NSString *)newPwd
{
    serviceType = Ants_ResivePwd;
    [self connection:@"ResivePwd" :@{@"encodeName":[clsOtherFun getencodeName],@"newPwd":newPwd}];
}
- (void)GetQuestionType
{
    serviceType = Ants_GetQuestionType;
    [self connection:@"GetQuestionType" :@{}];
}
- (void)GetQuestionListTxt:(NSString *)oid
{
    serviceType = Ants_GetQuestionListTxt;
    [self connection:@"GetQuestionListTxt" :@{@"id":[NSString stringWithFormat:@"%ld",(long)[oid integerValue]]}];

}
-(void)GetQuestioTitle:(NSString*)oid
{
    serviceType = Ants_GetQuestioTitle;
    [self connection:@"GetQuestioTitle" :@{@"id":oid}];
}
- (void)GetCity:(NSString *)pid action:(void(^)(NSDictionary *dic))action
{
    self.action =action;
    serviceType = Ants_GetCity;
    [self connection:@"GetCity" :@{@"pid":pid}];
}
- (void)GetProvince:(void(^)(NSDictionary *dic))action
{
    self.action =action;
    serviceType = Ants_GetProvince;
    [self connection:@"GetProvince" :@{}];
}
- (void)GetDistrict:(NSString *)cid action:(void(^)(NSDictionary *dic))action
{
    self.action =action;
    serviceType = Ants_GetDistrict;
    [self connection:@"GetDistrict" :@{@"cid":cid}];
}
- (void)SaveSendExpress:(NSString *)sName :(NSString *)sTelephone :(NSString *)sProvince :(NSString *)sCity :(NSString *)sDistrict :(NSString *)sAdress :(NSString *)uid :(NSString *)memberName :(NSString *)goodsName :(NSString *)province :(NSString *)city :(NSString *)district :(NSString *)isBJ :(NSString *)adress :(NSString *)Telephone
{
    serviceType = Ants_SaveSendExpress;
    
    [self connection:@"SaveSendExpress" :@{@"sName":sName,@"sTelephone":sTelephone,@"sProvince":[NSString stringWithFormat:@"%ld",[sProvince integerValue]],@"sCity":[NSString stringWithFormat:@"%ld",[sCity integerValue]],@"sDistrict":[NSString stringWithFormat:@"%ld",[sDistrict integerValue]],@"sAdress":sAdress,@"uid":[NSString stringWithFormat:@"%ld",[uid integerValue]],@"memberName":memberName,@"goodsName":goodsName,@"province":[NSString stringWithFormat:@"%ld",[province integerValue]],@"city":[NSString stringWithFormat:@"%ld",[city integerValue]],@"district":[NSString stringWithFormat:@"%ld",[district integerValue]],@"isBJ":isBJ,@"adress":adress,@"Telephone":Telephone}];
}
- (void)DeleteSendExpress :(NSString *)SendExpressMember action:(void(^)(NSDictionary *dic))action
{
    self.action =action;
    serviceType = Ants_DeleteSendExpress;
    [self connection:@"DeleteSendExpress" :@{@"SendExpressMember":SendExpressMember}];
}
- (void)UpdateSendExpress:(NSString *)sName :(NSString *)sTelephone :(NSString *)sProvince :(NSString *)sCity :(NSString *)sDistrict :(NSString *)sAdress :(NSString *)uid :(NSString *)memberName :(NSString *)goodsName :(NSString *)province :(NSString *)city :(NSString *)district :(NSString *)isBJ :(NSString *)adress :(NSString *)ID :(NSString *)Telephone
{
    serviceType = Ants_UpdateSendExpress;
    [self connection:@"UpdateSendExpress" :@{@"sName":sName,@"sTelephone":sTelephone,@"sProvince":sProvince,@"sCity":sCity,@"sDistrict":sDistrict,@"sAdress":sAdress,@"uid":uid,@"memberName":memberName,@"goodsName":goodsName,@"province":province,@"city":city,@"district":district,@"isBJ":isBJ,@"adress":adress,@"ID":ID,@"Telephone":Telephone}];
}
- (void)GetAppNewVersion
{
    serviceType = Ants_GetAppNewVersion;
    
    [self connection:@"GetAppNewVersion" :@{@"version":[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"],@"DeviceType":@"0"}];
}
- (void)DeviceLoadImg:(void(^)(NSDictionary *dic))action
{
    serviceType = Ants_DeviceLoadImg;
    self.action = action;
    [self connection:@"DeviceLoadImg" :@{@"IsFirst":[clsOtherFun getIsFirstRun]?@"0":@"1"}];
}
#pragma mark connection Callbacks
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [webData setLength: 0];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [webData appendData:data];
}

//如果电脑没有连接网络，则出现此信息（不是网络服务器不通）
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    theConnection = nil;
    webData = nil;
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataFail:)]) {
        [self.delegate getAntsDataFail:serviceType];
    }
    
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    theConnection = nil;
    dictionary = [NSMutableDictionary dictionary];
    NSString * data=[[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
    NSLog(@"return:%@",data);
    NSError * error=nil;
    if(webData){
        id obj=[NSJSONSerialization JSONObjectWithData:webData options:NSJSONReadingAllowFragments error:&error];
        if (error) {
            [self connectionFail];
            return;
        }
        if ([obj isKindOfClass:[NSDictionary class]]) {
            NSDictionary * dic=(NSDictionary *) obj;
            if(dic){
                if (serviceType==Ants_GetSlideBox) {
                    NSArray *arr = [dic objectForKey:@"data"];
                    NSMutableArray *list = [NSMutableArray arrayWithArray:arr];
                    [dictionary setObject:list forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_Register) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_GetHotNews) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_GetProblemExpressList) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_GetProbleExpressByid) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_GetUserInfo) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_GetQuHuoAdress) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_GetHotNewsEntity) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_Login) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if (serviceType==Ants_GetPickUpPoint) {
                    [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }else if(serviceType ==Ants_GetProvince){
                    if(self.action)
                        self.action(dic);
                }else if(serviceType ==Ants_GetCity){
                    if(self.action)
                        self.action(dic);
                }else if(serviceType ==Ants_GetDistrict){
                    if(self.action)
                        self.action(dic);
                }else if(serviceType ==Ants_DeleteSendExpress){
                    if(self.action)
                        self.action(dic);
                }else if(serviceType ==Ants_DeviceLoadImg){
                    if(self.action)
                        self.action(dic);
                }
                else{
                     [dictionary setObject:dic forKey:@"data"];
                    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                        [self.delegate getAntsDataSuccess:serviceType :dictionary];
                    }
                }
               
            }
        }else if ([obj isKindOfClass:[NSArray class]]){
            NSArray *arr = (NSArray *)obj;
            [dictionary setObject:arr forKey:@"data"];
            if (serviceType==Ants_GetAreaList) {
                if(self.action)
                    self.action(dictionary);
            }else if (serviceType==Ants_GetWareList) {
                if(self.action)
                    self.action(dictionary);
            }else if (serviceType==Ants_GetBranchList) {
            
                if(self.action)
                    self.action(dictionary);
            }else if (serviceType==Ants_GetBranchLists){
                if (self.action) {
                    self.action(dictionary);
                }
            }
            else{
            if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataSuccess::)]) {
                [self.delegate getAntsDataSuccess:serviceType :dictionary];
            }
            }
        }
        
    }
}
-(void) connectionFail{
    if (self.delegate && [self.delegate respondsToSelector:@selector(getAntsDataFail:)]) {
        [self.delegate getAntsDataFail:serviceType];
    }
}

- (void)cancel {
    if (theConnection) {
        [theConnection cancel];
    }
    theConnection = nil;
    webData = nil;
    dictionary = nil;
}
@end
